package dao

type Partner struct {
	GormModel
	Name           string `gorm:"type:varchar" json:"name"`
	Email          string `gorm:"type:varchar" json:"email"`
	FBaddress      string `gorm:"type:varchar;column:fbaddress" json:"FBaddress"`
	Product        string `gorm:"type:varchar" json:"product" `
	HistoryOrderNo string `gorm:"type:varchar;column:historyOrderNo" json:"historyOrderNo"`
	ReviewLinker   string `gorm:"type:varchar;column:reviewLinker" json:"reviewLinker"`
	Createuserid   int    `gorm:"type:int" json:"createuserid"`
}

func (p *Partner) FetchByUser(userid int) (list []Partner) {
	db.Where("createuserid=?", userid).Find(&list)
	return
}

func (p *Partner) FetchByAdmin() (list []Partner) {
	db.Find(&list)
	return
}

func (p *Partner) FetchByLeader(userid int) (list []Partner) {
	//db.Where("createuserid in (?)", users).Find(&list)
	db.Table("partner").Select("partner.*").Joins("left join managerelation on managerelation.Cid = partner.createuserid").Where("managerelation.mid=?", userid).Scan(&list)
	return
}

func (p *Partner) Insert() (err error) {
	err = db.Create(p).Error
	return
}

func (p *Partner) Update() (err error) {
	err = db.Save(p).Error
	return
}
